package com.leo.customer.config

import com.alibaba.druid.pool.DruidDataSource
import com.alibaba.druid.support.http.StatViewServlet
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.web.servlet.ServletRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.sql.DataSource

@Configuration
class DruidConfig {

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.druid")
    public fun druidDataSource(): DataSource {
        return DruidDataSource()
    }

    @Bean
    public fun statViewServlet(): ServletRegistrationBean<StatViewServlet> {
        val bean = ServletRegistrationBean(StatViewServlet(), "/druid/**")
        bean.addInitParameter("loginUsername", "admin")
        bean.addInitParameter("loginPassword", "123456")
        bean.addInitParameter("allow", "")
        bean.addInitParameter("reserEnable", "false")
//        bean.addInitParameter("deny","")
        return bean
    }
}
